package com.jiazhong.mingxing.boot.boot11.普通消息.消息生产;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

@Slf4j
public class 单向消息生产 {
    @SneakyThrows
    public static void main(String[] args) {
        DefaultMQProducer producer = new DefaultMQProducer("jiazhong-c");
        producer.setNamesrvAddr("124.220.170.254:9876");
        producer.start();
        for (int i = 1; i < 21; i++) {
            String topic = "TopicA";
            String tags = "oneway";
            String body = "こんにちは、RocketMQ!私は" + i + "のメッセージです";
            Message message = new Message(topic, tags, body.getBytes(StandardCharsets.UTF_8));
            producer.sendOneway(message);
        }
        producer.shutdown();
    }
}
